<template>
	<view class="home">
		<view class="register">
			<view class="head">
				<image :src='msg_head' mode=""></image>
			</view>

			<view class="telephone_number positon" >
				<view class="">姓名:</view>
				<input type="text" v-model="register_message.Re_name" placeholder="例如:小明" maxlength="4"/>
			</view>
			
			<view class="telephone_number positon">
				<view class="">身份证:</view>
				<input type="number" v-model="register_message.ID" placeholder="请输入身份证号" maxlength="18"/>
			</view>
		
			<view class="telephone_number" >
				<view class="">手机号码:</view>
				<input type="number" value="" placeholder="请输入手机号码"/>
			</view>
		
			<!-- <view class="upload">
				<view class="">添加校园卡:</view>
				<image :src="msg_campus_special" mode="" @click="special"></image>
			</view> -->
			
			<view class="check telephone_number">
				<view class="">短信验证:</view>
				<input type="text" value="" placeholder="请输入验证码"/>
				<button type="primary" @click="send_SMS" class="send_SMS">点击发送</button>
			</view>
		
			<button type="primary" class="button" @click="revise">注册跑手</button>
		
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msg_head: '../../static/temp/head.png',
				User_number:'',
				register_message:{
					Re_name:'',
					ID:''
				}
			}
		},
		methods: {
			send_SMS(){
				console.log('发送短信啦')
			},
			async revise(){
				if(this.register_message.Re_name == '' || this.register_message.ID == '' || this.register_message.ID.length != 18){
					return;
				}
				
				// 改成全局接口请求的封装
				let url = 'http://3888n9t950.wicp.vip/revise_ifRunner';
				// const res = await this.$myRequest({
				// 	url: `/revise_ifRunner?number=${this.User_number}&message=${JSON.stringify(this.register_message)}`
				// })
				const res = await uni.request({
					url:`${url}?number=${this.User_number}&message=${JSON.stringify(this.register_message)}`
				})
				console.log(res);
				if(res[1].data.code == -1 && res[1].data.message == -1){
					uni.showToast({
						title:'注册失败!输入有误哦',
						success:()=>{
							this.register_message.ID = '';
							this.register_message.Re_name = '';
							return;
						}
					})
				}else{
					let temp = res[1].data.message;
					uni.showToast({
						title: '注册成功!',
						success:()=>{
							uni.$emit('give_reivse_UserMessage',temp);
							getApp().globalData.User = temp;
						}
					})
					let id = setInterval(()=>{
						uni.switchTab({
							url:'../../pages/personal_center/personal_center'
						})
						clearInterval(id);
					},1000)
				}
			}
		},
		onLoad(options) {
			console.log(options);
			this.User_number = options.number;
		}
	}
</script>

<style lang="scss">
	.home{
		width: 100%;
		font-size: 28rpx;
		.register {
			width: 90%;
			margin: 100rpx auto;
			padding: 20rpx 20rpx;
			border: 1px solid #808080;
			border-radius: 20rpx;
			box-sizing: border-box;
		
			.head {
				image {
					display: block;
					width: 150rpx;
					height: 150rpx;
					margin: 0 auto;
					border-radius: 80rpx;
				}
		
			}
			
			
		
		
			.telephone_number {
				display: flex;
				align-items: center;
				width: 100%;
				margin-bottom: 13rpx;
				height: 100rpx;
				line-height: 100rpx;
				margin-top: 30rpx;
				border-bottom: 1px solid #C0C0C0;
		
				view {
					width: 150rpx;
					text-align: right;
					padding-right: 20rpx;
				}
		
				input {
					display: flex;
					flex: 1;
					height: 100rpx;
					border-radius: 6rpx;
					padding-left: 15rpx;
				}
					button{
						width: 95px;
						height: 60rpx;
						line-height: 60rpx;
						font-size: 20rpx;
						margin-right: 10rpx;
						margin-left: 5rpx;
						background-color: $main-color;
					}
			}
		
		
			.button {
				margin-top: 140rpx;
				width: 90%;
				height: 80rpx;
				font-size: 30rpx;
				border-radius: 40rpx !important;
				background-color: $main-color;
			}
			button::after{
				border: none;
			}
		}
	}
</style>
